#ifndef __GAF_PLAYER_H__
#define __GAF_PLAYER_H__

namespace GAF
{
	class PlayerResponse;
	//class Runnable
		class Player;
}
typedef GAF::PlayerResponse		GAF_IPlayerResponse;
typedef GAF::Player			GAF_CPlayer;

namespace GAF
{
	enum PlayerState
	{
		PLAYER_PLAY,		// 播放状态
		PLAYER_RUN,		// 运行状态
		PLAYER_PAUSE,		// 暂停状态
		PLAYER_FINISH,		// 完成状态
		PLAYER_STOP,		// 停止状态
	};
}
typedef GAF::PlayerState		GAF_EPlayerState;
#define GAF_PLAYER_PLAY			GAF::PLAYER_PLAY
#define GAF_PLAYER_RUN			GAF::PLAYER_RUN
#define GAF_PLAYER_PAUSE		GAF::PLAYER_PAUSE
#define GAF_PLAYER_FINISH		GAF::PLAYER_FINISH
#define GAF_PLAYER_STOP			GAF::PLAYER_STOP


#include "GAF_Define.h"
#include "GAF_Timer.h"
#include "GAF_Bundle.h"

namespace GAF
{
	/// 动画效果响应处理接口
	class _INTERFACE PlayerResponse
	{
	public:
		/// 当播放对象响应时
		virtual void		OnPlayerResponse(GAF_CPlayer* pPlayer, UINT nState) = 0;
	};

	/// 可播放对象基类
	class _ABSTRACT Player : public Runnable
	{
	private:
		// 自动名称序号
		static UINT		GetID();
		static UINT		m_nID;

	public:
		Player();
		virtual ~Player();

	public:
		/// 设置响应处理类
		void			SetResponse(PlayerResponse* pResponse);
		/// 精确计时
		void			ExactTimer();

	public:
		/// 播放对象
		void			Play(Bundle* pbdlParam = NULL);
		/// 暂停对象
		void			Pause();
		/// 停止对象
		void			Stop();
	private:
		/// 完成对象
		void			Finish();

		/**
		 *  @name 操作
		 */
		// 定义操作
	protected:
		/// 播放操作
		virtual bool		Playing(GAF_CBundle* pbdlParam)
					{return true;}
		/// 运行操作
		virtual bool		Running(TimeTicks ttUsed, bool& isFinish)
					{return true;}
		/// 暂停操作
		virtual bool		Pauseing()
					{return true;}
		/// 完成操作
		virtual bool		Finishing()
					{return true;}
		/// 停止操作
		virtual bool		Stopping()
					{return true;}

		/**
		 *  @name 事件成员
		 */
		// 定义事件
	protected:
		/// 当播放时
		virtual bool		OnPlay(GAF_CBundle* pbdlParam)
					{return true;}
		/// 当播放更新时
		virtual bool		OnUpdate(TimeTicks ttUsed)
					{return true;}
		/// 当播放暂停时
		virtual bool		OnPause()
					{return true;}
		/// 当完成一次播放时
		virtual bool		OnFinish()
					{return true;}
		/// 当播放停止时
		virtual bool		OnStop()
					{return true;}

	public:
		void			OnRun(RunBase* pRunBase);

	public:
		/// 名字属性
		DIM_ATTRIB_R(STD_STRING, PlayerName);
		/// 动画效果状态属性
		DIM_ATTRIB_R(PlayerState, State);
		/// 循环属性
		DIM_ATTRIB(bool, Loop);
		/// 动画效果间隔时间属性
		DIM_ATTRIB(TimeTicks, Interval);

	public:
		/// 设置播放对象名称
		void			SetPlayerName(STD_STRING strPlayerName);

	protected:
		/// 播放对象响应对象
		PlayerResponse*		m_pResponse;

	private:
		Timer*			m_pTimer;
		TimeTicks		m_ttLast;

		bool			m_isExactTimer;
	};
}

#endif
